<?php
/**
 * @version        $Id$
 * @author         master@xuewl.com
 * @copyright      Copyright (c) 2007 - 2013, Chongqing Zero Technology Co. Ltd.
 * @link           http://www.xuewl.com
**/
namespace Admin\Controller;
/* URL规则管理 */
Class IndexFocusController extends InitController {
    public function _initialize() {
    	parent::_initialize();
    	$this->db = D('IndexFocus');
    }

    /**
     * 幻灯管理
     * @author xuewl <master@xuewl.com>
     */
    public function manage() {
    	$page = max(1, (int) I('page'));
    	$sqlmap = array();
    	$count = $this->db->where($sqlmap)->count();
    	$infos = $this->db->where($sqlmap)->order("listorder DESC")->page($page, 10)->select();
    	$pages = page($count, $pages);
        include $this->admin_tpl('index_focus_manage');
    }

    /**
     * 幻灯添加
     * @author xuewl <master@xuewl.com>
     */
    public function add() {
        if (submitcheck('dosubmit')) {
            $info = $_POST['info'];
            $result = $this->db->update($info);
            if (!$result) {
                $this->error($this->db->getError());
            }
            $this->success('操作成功', U('manage'));
        } else {
            $show_header = FALSE;
            $form = new \Common\Library\form();
            include $this->admin_tpl('index_focus_add');
        }
    }

    /**
     * 幻灯编辑
     * @author xuewl <master@xuewl.com>
     */
    public function edit($id = 0) {
        $id = (int) $id;
        $row = $this->db->getById($id);
        if (!$row) $this->error('数据不存在');
        if (submitcheck('dosubmit')) {
            $info = $_POST['info'];
            $info['id'] = $id;
            $result = $this->db->update($info);
            if (!$result) {
                $this->error($this->db->getError());
            }
            $this->success('操作成功', U('manage'));
        } else {
            $show_header = FALSE;
            $form = new \Common\Library\form();
            include $this->admin_tpl('index_focus_edit');
        }
    }

    /**
     * 幻灯删除
     * @author xuewl <master@xuewl.com>
     */
    public function delete() {
    	if (submitcheck('dosubmit', 'GP')) {
    		$ids = I('id');
    		$sqlmap = array();
    		$sqlmap['id'] = array("IN", $ids);
	        $result = $this->db->where($sqlmap)->delete();
	        if (!$result) {
	            $this->error('数据删除失败');
	        }
	        $this->success('操作成功');    		
    	} else {
    		$this->error('请勿非法提交');
    	}
    }

    /**
     * 幻灯排序
     * @author xuewl <master@xuewl.com>
     */
    public function public_listorder() {
    	if (submitcheck('dosubmit', 'GP')) {
    		$listorders = I('listorder');
    		foreach ($listorders as $id => $listorder) {
    			$this->db->where(array('id' => $id))->setField('listorder', $listorder);
    		}
	        $this->success('操作成功');    		
    	} else {
    		$this->error('请勿非法提交');
    	}
    	
    }
}